package com.example.rabbitmqdemo.config;

import com.example.rabbitmqdemo.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-04-04
 * Time: 10:59
 */
@Configuration
public class DLconfig {
    //正常的交换机和队列
    @Bean("normalQueue")
    public Queue normalQueue() {
        return QueueBuilder
                .durable(Constants.NORMAL_QUEUE)
                .deadLetterExchange(Constants.DL_EXCHANGE)
                .deadLetterRoutingKey("dlx")
                .maxLength(10)
                .ttl(10000)
                .build();
    }

    @Bean("normalExchange")
    public DirectExchange normalExchange() {
        return ExchangeBuilder.directExchange(Constants.NORMAL_EXCHANGE).build();
    }

    @Bean("/normalBinding")
    public Binding normalBinding(@Qualifier("normalQueue") Queue queuem, @Qualifier("normalExchange") Exchange exchange) {
        return BindingBuilder.bind(queuem).to(exchange).with("normal").noargs();
    }

    //死信交换机和队列
    @Bean("dlQueue")
    public Queue dlQueue() {
        return QueueBuilder.durable(Constants.DL_QUEUE).build();
    }

    @Bean("dlExchange")
    public DirectExchange dlExchange() {
        return ExchangeBuilder.directExchange(Constants.DL_EXCHANGE).build();
    }

    @Bean("/dlBinding")
    public Binding dlBinding(@Qualifier("dlQueue") Queue queuem, @Qualifier("dlExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queuem).to(exchange).with("dlx");
    }
}
